package com.zqh.myfmmall.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-01-19 21:40
 */
@Data
@ApiModel("返回结果给前端VO类")
public class Result{
    @ApiModelProperty(value = "返回状态编码 200 操作成功；400 操作失败；401 权限不足；404 接口不存在；500 服务器内部错误；600 请重新登录")
    private String statusCode = ResultType.SUCCESS.getCode();

    @ApiModelProperty(value = "返回提示信息")
    private String message = ResultType.SUCCESS.getName();

    @ApiModelProperty(value = "返回结果数据")
    private Object data = null;

    @ApiModelProperty(value = "是否成功 true false")
    private Boolean success = true;



    public static Result success() {
        return Result.success(null);
    }

    public static Result success(String message) {
        return Result.success(message,null);
    }

    public static Result success(Object data) {
        return Result.success("", data);
    }

    public static Result success(String message,Object data) {
        Result result = new Result();
        result.setData(data);
        result.setStatusCode(ResultType.SUCCESS.getCode());
        if (message == null || "".equals(message)) {
            result.setMessage(ResultType.SUCCESS.getName());
        }else {
            result.setMessage(message);
        }
        return result;
    }

    public static Result fail() {
        return Result.fail(null);
    }

    public static Result fail(String message) {
        return Result.fail(message,null);
    }

    public static Result fail(Object data) {
       return Result.fail("",data);
    }

    public static Result fail(String message,Object data) {
        Result result = new Result();
        result.setData(data);
        result.setStatusCode(ResultType.FAIL.getCode());
        result.setSuccess(false);
        if (message == null || "".equals(message)) {
            result.setMessage(ResultType.FAIL.getName());
        }else {
            result.setMessage(message);
        }
        return result;
    }

    public static Result unauthorized() {
        return Result.unauthorized(null);
    }

    public static Result unauthorized(String message) {
        return Result.unauthorized(message,null);
    }

    public static Result unauthorized(Object data) {
        return Result.unauthorized("",data);
    }

    public static Result unauthorized(String message,Object data) {
        Result result = new Result();
        result.setData(data);
        result.setStatusCode(ResultType.UNAUTHORIZED.getCode());
        result.setSuccess(false);
        if (message == null || "".equals(message)) {
            result.setMessage(ResultType.UNAUTHORIZED.getName());
        }else {
            result.setMessage(message);
        }
        return result;
    }

    public static Result notFound() {
        return Result.notFound(null);
    }

    public static Result notFound(String message) {
        return Result.notFound(message,null);
    }

    public static Result notFound(Object data) {
        return Result.notFound("",data);
    }

    public static Result notFound(String message,Object data) {
        Result result = new Result();
        result.setData(data);
        result.setStatusCode(ResultType.NOT_FOUND.getCode());
        result.setSuccess(false);
        if (message == null || "".equals(message)) {
            result.setMessage(ResultType.NOT_FOUND.getName());
        }else {
            result.setMessage(message);
        }
        return result;
    }

    public static  Result internalServerError () {
        return Result.internalServerError(null);
    }

    public static Result internalServerError(String message) {
        return Result.internalServerError(message,null);
    }

    public static Result internalServerError(Object data) {
        return Result.internalServerError("",data);
    }

    public static Result internalServerError(String message,Object data) {
        Result result = new Result();
        result.setData(data);
        result.setStatusCode(ResultType.INTERNAL_SERVER_ERROR.getCode());
        result.setSuccess(false);
        if (message == null || "".equals(message)) {
            result.setMessage(ResultType.INTERNAL_SERVER_ERROR.getName());
        }else {
            result.setMessage(message);
        }
        return result;
    }



    public static Result againLogin() {
        return Result.againLogin(null);
    }

    public static Result againLogin(String message) {
        return Result.againLogin(message,null);
    }

    public static Result againLogin(Object data) {
        return Result.againLogin("",data);
    }

    public static Result againLogin(String message,Object data) {
        Result result = new Result();
        result.setData(data);
        result.setStatusCode(ResultType.AGAIN_LOGIN.getCode());
        result.setSuccess(false);
        if (message == null || "".equals(message)) {
            result.setMessage(ResultType.AGAIN_LOGIN.getName());
        }else {
            result.setMessage(message);
        }
        return result;
    }
}
